package com.briup.jz.service.impl;

import com.briup.jz.bean.*;
import com.briup.jz.dao.BaseRolePrivilegeMapper;
import com.briup.jz.dao.BaseUserMapper;
import com.briup.jz.service.IBaseUserService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseUserServiceImpl implements IBaseUserService {

    @Autowired
    private BaseUserMapper baseUserMapper;


    @Override
    public void saveOrUpdate(BaseUser baseUser) throws CustomerException {
        if (baseUser.getId()==null){
            baseUserMapper.insert(baseUser);
        }else{
            baseUserMapper.updateByPrimaryKey(baseUser);
        }
    }

    @Override
    public List<BaseUser> query(String username,String status,Long roleId) throws CustomerException {
        BaseUserExample example = new BaseUserExample();
        BaseUserExample.Criteria criteria = example.createCriteria();
        if(username!=null){
            criteria.andUsernameLike("%"+username+"%");
        }
        if(status!=null){
            criteria.andStatusEqualTo(status);
        }
        return baseUserMapper.selectByExample(example);
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        BaseUser user = baseUserMapper.selectByPrimaryKey(id);
        if (user==null){
            throw new CustomerException("该用户信息不存在");
        }
        baseUserMapper.deleteByPrimaryKey(id);
    }
}
